import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useState } from "react";
import classes from "./myReferral.module.less";
import SecondaryLayout from "../../compoents/secondary-layout";
import ScrollView from "../../compoents/scroll-view";
import { useSelector } from "react-redux";
import { useClipboard } from "use-clipboard-copy";
import toast from "../../compoents/toast";
import useServices from "../../hooks/useRequest";
import { getInviterList } from "../../api/user";
import { useMount } from "ahooks";
import { useTranslation } from "react-i18next";
import { LocalKeyMap } from "../../local";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function MyReferral() {
    var _useSelector = useSelector(function(state) {
        return {
            userInfo: state.app.userInfo,
            theme: state.app.theme
        };
    }), userInfo = _useSelector.userInfo, theme = _useSelector.theme;
    var copy = useClipboard({
        onSuccess: function() {
            toast.copy();
        },
        onError: function() {}
    }).copy;
    var t = useTranslation().t;
    var services = useServices({
        getInviterList: getInviterList
    });
    var _useState = _sliced_to_array(useState([]), 2), guilds = _useState[0], setGuilds = _useState[1];
    var fetchGuilds = function() {
        services.getInviterList().then(function(res) {
            if (res.code == 200) {
                setGuilds(res.data.list || []);
            }
        });
    };
    useMount(fetchGuilds);
    return /*#__PURE__*/ _jsx(SecondaryLayout, {
        title: t(LocalKeyMap["myReferral.title"]),
        children: /*#__PURE__*/ _jsx("div", {
            className: classes.my_referral,
            children: /*#__PURE__*/ _jsxs("div", {
                className: classes.my_referral_content,
                children: [
                    /*#__PURE__*/ _jsxs("div", {
                        className: classes.referral_box,
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.title,
                                children: t(LocalKeyMap["myReferral.friends"], {
                                    guilds: guilds.length
                                })
                            }),
                            guilds.length ? /*#__PURE__*/ _jsx(ScrollView, {
                                className: classes.referral_list,
                                wrapperClassName: classes.d_inline_block,
                                scrollX: true,
                                children: /*#__PURE__*/ _jsx("div", {
                                    className: classes.scroll_content,
                                    children: guilds.map(function(item) {
                                        return /*#__PURE__*/ _jsxs("div", {
                                            className: classes.referral_item,
                                            children: [
                                                /*#__PURE__*/ _jsx("img", {
                                                    src: item.avatarLink,
                                                    className: classes.avatar
                                                }),
                                                /*#__PURE__*/ _jsx("div", {
                                                    className: classes.name,
                                                    children: item.nickname
                                                })
                                            ]
                                        }, item.id);
                                    })
                                })
                            }) : /*#__PURE__*/ _jsx("div", {
                                className: classes.not_guild,
                                children: /*#__PURE__*/ _jsx("span", {
                                    children: t(LocalKeyMap["myReferral.empty"])
                                })
                            })
                        ]
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: classes.referral_code_box,
                        children: [
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.title,
                                children: t(LocalKeyMap["personalInformation.referralTitle"])
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.desc,
                                children: t(LocalKeyMap["personalInformation.referralDesc"])
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classes.code,
                                children: userInfo.did
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                onClick: function() {
                                    copy(userInfo.did);
                                },
                                className: classes.btn,
                                children: /*#__PURE__*/ _jsx("span", {
                                    children: t(LocalKeyMap.copy)
                                })
                            })
                        ]
                    })
                ]
            })
        })
    });
}
export default MyReferral;

 //# sourceMappingURL=index.js.map